 package server.console.groups.datamanage;
 import com.alee.laf.rootpane.WebFrame;
import constants.ItemConstants;
import server.MapleItemInformationProvider;
import server.life.MapleLifeFactory;
import server.shop.MapleShop;
import server.shop.MapleShopFactory;
import server.shop.MapleShopItem;
import tools.Pair;

import javax.swing.table.DefaultTableModel;
import java.util.*;















 class NPCShopPane extends TabbedPane {
/*  18 */   final Map<Integer, MapleShop> shops = MapleShopFactory.getInstance().getAllShop();
/*  19 */   private final Map<String, List<Pair<DataMamageMode, Vector<String>>>> changelist = new LinkedHashMap<>();
   private DefaultTableModel defaultTableModel_ID;

   NPCShopPane(WebFrame owner) {
/*  23 */     super(owner);
   }


   void init() {
/*  28 */     this.idTableName.add("商店ID");
/*  29 */     this.idTableName.add("NPCID");

/*  31 */     this.dataTableName.add("位置");
/*  32 */     this.dataTableName.add("道具ID");
/*  33 */     this.dataTableName.add("道具名称");
/*  34 */     this.dataTableName.add("游戏币价格");
/*  35 */     this.dataTableName.add("特殊货币ID");
/*  36 */     this.dataTableName.add("特殊货币数量");
/*  37 */     this.dataTableName.add("有效时间");
/*  38 */     this.dataTableName.add("潜能状态");
/*  39 */     this.dataTableName.add("分类");
/*  40 */     this.dataTableName.add("可购买的最小等级");

/*  42 */     Vector<Vector<String>> shopList = new Vector<>();
/*  43 */     for (Map.Entry<Integer, MapleShop> entry : this.shops.entrySet()) {
/*  44 */       Vector<String> data = new Vector<>();
/*  45 */       data.add(String.valueOf(entry.getKey()));
/*  46 */       data.add(String.valueOf(((MapleShop)entry.getValue()).getNpcId()));
/*  47 */       shopList.add(data);
     }
/*  49 */     this.defaultTableModel_ID = new DefaultTableModel(shopList, this.idTableName);
   }


   String getTitle() {
/*  54 */     return "NPC商店";
   }



   protected DefaultTableModel getIDTableModel() {
/*  60 */     return this.defaultTableModel_ID;
   }


   protected Vector<String> getDefaultDataVector() {
/*  65 */     Vector<String> ret = new Vector<>();
/*  66 */     ret.add("");
/*  67 */     ret.add("");
/*  68 */     ret.add("");
/*  69 */     ret.add("0");
/*  70 */     ret.add("0");
/*  71 */     ret.add("0");
/*  72 */     ret.add("0");
/*  73 */     ret.add("0");
/*  74 */     ret.add("0");
/*  75 */     ret.add("0");
/*  76 */     return ret;
   }


   protected DefaultTableModel getDataTableModel() {
/*  81 */     MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
/*  82 */     Vector<Vector<String>> datas = new Vector<>();
/*  83 */     if (this.idTable.getSelectedRow() > -1) {
/*  84 */       String id = (String)this.idTable.getValueAt(this.idTable.getSelectedRow(), 0);
/*  85 */       if (this.shops.containsKey(Integer.valueOf(id))) {
/*  86 */         for (MapleShopItem mapleShopItem : ((MapleShop)this.shops.get(Integer.valueOf(id))).getItems()) {
/*  87 */           if (mapleShopItem.isRechargeableItem()) {
             continue;
           }
/*  90 */           Vector<String> data = new Vector<>();
/*  91 */           data.add(String.valueOf(mapleShopItem.getPosition()));
/*  92 */           data.add(String.valueOf(mapleShopItem.getItemId()));
/*  93 */           data.add(ii.getName(mapleShopItem.getItemId()));
/*  94 */           data.add(String.valueOf(mapleShopItem.getPrice()));
/*  95 */           data.add(String.valueOf(mapleShopItem.getReqItem()));
/*  96 */           data.add(String.valueOf(mapleShopItem.getReqItemQ()));
/*  97 */           data.add(String.valueOf(mapleShopItem.getPeriod()));
/*  98 */           data.add(String.valueOf(mapleShopItem.getState()));
/*  99 */           data.add(String.valueOf(mapleShopItem.getCategory()));
/* 100 */           data.add(String.valueOf(mapleShopItem.getMinLevel()));
/* 101 */           datas.add(data);
         }
       }
     }

/* 106 */     return new DefaultTableModel(datas, this.dataTableName);
   }


   protected String getIDName(String id) {
     try {
/* 112 */       if (this.shops.containsKey(Integer.valueOf(id))) {
/* 113 */         int npcid = ((MapleShop)this.shops.get(Integer.valueOf(id))).getNpcId();
/* 114 */         return npcid + " - " + MapleLifeFactory.getNpcName(npcid);
       }
/* 116 */       return null;
     }
/* 118 */     catch (NumberFormatException e) {
/* 119 */       return null;
     }
   }


   protected String getDataName(String id) {
     try {
/* 126 */       return MapleItemInformationProvider.getInstance().getName(Integer.valueOf(id).intValue());
/* 127 */     } catch (NumberFormatException e) {
/* 128 */       return null;
     }
   }


   protected boolean hasNameIDTable(int i) {
/* 134 */     return false;
   }


   protected boolean hasNameDataTable(int i) {
/* 139 */     return (i == 1);
   }


   protected void addToChangeList(DataMamageMode mode, String id, Vector<String> row) {
     List<Pair<DataMamageMode, Vector<String>>> oldrow;
/* 145 */     if (this.changelist.containsKey(id)) {
/* 146 */       oldrow = this.changelist.get(id);
     } else {
/* 148 */       oldrow = new LinkedList<>();
     }
/* 150 */     oldrow.add(new Pair(mode, row));
/* 151 */     this.changelist.put(id, oldrow);
/* 152 */     this.button_apply.setEnabled(true);
   }


   protected void applyChange(boolean change) {
/* 157 */     if (!this.changelist.isEmpty())

       try {

/* 161 */         for (Map.Entry<String, List<Pair<DataMamageMode, Vector<String>>>> entry : this.changelist.entrySet()) {
/* 162 */           String shopid = entry.getKey();
/* 163 */           for (Pair<DataMamageMode, Vector<String>> pair : entry.getValue()) {
/* 164 */             boolean isRecharge; MapleShopItem mapleShopItem; DataMamageMode mode = (DataMamageMode)pair.getLeft();
/* 165 */             Vector<String> row = (Vector<String>)pair.getRight();
/* 166 */             MapleShop shop = null;
/* 167 */             switch (mode) {
               case ID_编辑:
               case ID_删除:
/* 170 */                 if (!this.shops.containsKey(Integer.valueOf(shopid))) {
/* 171 */                   shop = new MapleShop(Integer.valueOf(row.get(0)).intValue(), Integer.valueOf(row.get(1)).intValue());
/* 172 */                   this.shops.put(Integer.valueOf(shopid), shop); break;
                 }
/* 174 */                 this.shops.remove(Integer.valueOf(shopid));
                 break;

               case DATA_编辑:
/* 178 */                 if (row.size() != this.dataTableName.size()) {
/* 179 */                   throw new RuntimeException("NPCShop row index error");
                 }
/* 181 */                 isRecharge = (ItemConstants.is飞镖道具(Integer.parseInt(row.get(1))) || ItemConstants.is子弹道具(Integer.parseInt(row.get(1))));











/* 193 */                 mapleShopItem = new MapleShopItem((short)(isRecharge ? 1 : 1000), Integer.parseInt(row.get(1)), Integer.parseInt(row.get(3)), Integer.parseInt(row.get(4)), Integer.parseInt(row.get(5)), 0, Integer.parseInt(row.get(6)), Integer.parseInt(row.get(7)), Integer.parseInt(row.get(8)), Integer.parseInt(row.get(9)), Integer.parseInt(row.get(0)), isRecharge);

/* 195 */                 if (this.shops.containsKey(Integer.valueOf(shopid))) {
/* 196 */                   shop = this.shops.get(Integer.valueOf(shopid));
/* 197 */                   shop.getItems().removeIf(item -> (item.getItemId() == mapleShopItem.getItemId()));
/* 198 */                   shop.addItem(mapleShopItem); break;
                 }
/* 200 */                 throw new RuntimeException("未找到商店数据");



               case DATA_删除:
/* 205 */                 if (this.shops.containsKey(Integer.valueOf(shopid))) {
/* 206 */                   shop = this.shops.get(Integer.valueOf(shopid));
/* 207 */                   shop.getItems().removeIf(item -> (item.getPosition() == Integer.parseInt(row.get(0)) && item.getItemId() == Integer.parseInt(row.get(1))));
                 }
                 break;
             }
/* 211 */             if (shop == null) {
/* 212 */               MapleShopFactory.getInstance(); MapleShopFactory.removeShop(Integer.parseInt(shopid));
             } else {
/* 214 */               MapleShopFactory.getInstance(); MapleShopFactory.updateShop(shop);
             }

/* 217 */             MapleShopFactory.getInstance().clear();
           }
         }
       } finally {

/* 222 */         this.changelist.clear();
       }
   }
 }


/* Location:              C:\PGX\Server.jar!\server\console\groups\datamanage\NPCShopPane.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */